// TOWN SCRIPT
//    Town 14: Epilogue

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

short i,choice;
short j = 0;
short lead_char;

body;

beginstate INIT_STATE;
// This state called whenever this town is entered

 set_name(6,"Arivan");
 set_name(7,"Olander");
 set_name(8,"Nablar");

 set_level(6,1);

 i = 0;
 while (i < 5) {
  if (char_ok(i)) {
   lead_char = i;
   i = 5;
  }
  else
   i = i + 1;
 }

 if (get_sdf(5,10) == 0) {
  force_instant_terrain_redraw();
  set_flag(5,10,1);
  message_dialog("You step into the teleporter and find yourself back in the Resistance Cave. The teleporter in the mine must have locked onto this one and sent you back here.","You look around and you notice a lot of rock has fallen from the ceiling. Some major event, like a large explosion or an earthquake must have occurred while you were away.");
 }

 set_crime_tolerance(1);

break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;

 if ((get_ran(1,0,100) < 30) && (get_attitude(6) == 4))
		text_bubble_on_char(6,"Ooow!");
 if ((get_ran(1,0,100) < 40) && (get_attitude(6) == 4))
		text_bubble_on_char(6,"Ungh...");

 if ((get_ran(1,0,100) < 7) && (get_attitude(7) == 3))
		text_bubble_on_char(7,"Why, Klinger?");
 if ((get_ran(1,0,100) < 7) && (get_attitude(7) == 3))
		text_bubble_on_char(7,"So pointless...");

 if ((get_ran(1,0,100) < 14) && (get_attitude(8) == 3))
		text_bubble_on_char(8,". . .");

 if (get_sdf(5,15) == 1)
  j = j + 1;

 if ((get_sdf(5,15) == 1) && (j >= 3)) {
  set_flag(5,15,2);
  set_state_continue(19);
 }

break;


beginstate 10;

message_dialog("This teleporter is very weak now. You are not sure if this was caused by you using it or the event that followed. Either way, it cannot take you anywhere anymore.","");
block_entry(1);

break;


beginstate 11;

if (get_sdf(5,11) == 0) {
 set_flag(5,11,1);
 message_dialog("The body of the traitor is still here. You give it a nice firm kick for good measure.","");
}

break;


beginstate 12;

if (get_sdf(5,12) == 0) {
 set_flag(5,12,1);
 message_dialog("You must be getting closer to the center of whatever occurred. The cave-in was far more intense in this area. You struggle to make your way over the dense rubble from overhead.","");
}

break;


beginstate 13;

if ((char_ok(6) == 1) && (get_sdf(5,13) == 0)) {
 erase_text_bubbles();
 force_instant_terrain_redraw();
 set_flag(5,13,1);
 reset_dialog();
 add_dialog_str(0,"You enter the Resistance temple and you see the battered body of Arivan pressed against the altar. She appears to have been crushed by some violent force. Her fur is heavily singed as if by some fiery explosion.",0);
 add_dialog_str(1,"It is remarkable that she is still alive. A light aura surrounds her. You guess that her protective magic has been preserving her life, but she is in very rough shape. She probably will not last much longer.",0);
 add_dialog_str(2,"She turns and glares at you with an off center stare. It takes her a while to comprehend the situation. _You? You were supposed to be killed._",0);
 add_dialog_choice(0,"You failed! Now we will have our revenge! (Kill her)");
 add_dialog_choice(1,"We survived. Let us help you. (Try to heal her)");
 if (has_item_of_class(2,0) == 1)
  add_dialog_choice(2,"We found this bracelet with your rune on it. Know anything about it? (Show her the Bracelet)");
 else
  add_dialog_choice(2,"Leave Arivan to her misery.");
 choice = run_dialog(1);
 if (choice == 1)
  set_state_continue(14);
 if (choice == 2)
  set_state_continue(15);
 if (choice == 3)
  set_state_continue(16);
 
}

break;


beginstate 14;

relocate_character(lead_char,52,28);
set_character_facing(lead_char,0);
force_instant_terrain_redraw();
pause(5);
set_character_pose(lead_char,1);
play_sound(69);
message_dialog("Arivan spurts, _I have no regrets._","You plunge your weapon into Arivan's dark, twisted heart. The fiend quickly dies, not as if she had much time left anyway. At least you got to make the fatal blow upon her.");
kill_char(6,2,0);
set_character_pose(lead_char,0);
block_entry(1);

break; 


beginstate 15;

put_sparkles_on_char(6,3,8);
force_instant_terrain_redraw();
run_animation_sound(24);
pause(5);
message_dialog("You attempt to heal her, but she is too damaged for your magic to take effect. _Too late for that now..._","Arivan hacks loudly as she speaks. _I may go...cannot be stopped...far too strong...worse than..._ Arivan's lowers her head as her glow fades away. She is dead.");
erase_char(6);

break; 


beginstate 16;

if (has_item_of_class(2,1) == 1) {
 reset_dialog();
 add_dialog_str(0,"_My bracelet!_ she hacks. _Where?_ You tell her where you got it She looks down. _Lost that there, so long ago..._ She lowers her head and thinks. _May I hold it?_.",0);
 add_dialog_str(1,"You grant her request. _So many memories stolen..._ She paws the bracelet affectionately. Her eyes look as if she discovered some forgotten past, some dark hidden truth.",0);
 add_dialog_str(2,"You see her shed a tear as she murmurs, _Suvar..._ She drops the bracelet as her body slumps to the ground. All light vanishes from her eyes and the glow surrounding her grows dark. Arivan is dead.",0);
 add_dialog_choice(0,"Take back the bracelet.");
 add_dialog_choice(1,"Leave it respectfully with her body.");
 choice = run_dialog(1);
 if (choice == 1)
  reward_give(452);
 if (choice == 2)
  award_party_xp(200,5);
}
else {
 message_dialog("You ignore her. She stares at you coldly as her breathing becomes hoarse. She hacks loudly and her body slumps lifelessly. The menace is now dead.","");
}
erase_char(6);

 
break; 


beginstate 17;

if (get_sdf(5,13) == 0) {
 set_state_continue(13);
 block_entry(1);
 end();
}

if (get_sdf(5,14) == 0) {
 set_flag(5,14,1);
 reset_dialog();
 add_dialog_str(0,"You now get a better look of the scene. Charred and battered bodies are everywhere, many of them trapped under the bebris. The surfaces of this room are heavily scorched as if there was some big explosion here.",0);
 add_dialog_str(1,"Among all the rubble and carnage, you find a single bow that has survived. You recognize it. This was Klinger's bow. You hope for the best, but you doubt his fate was good.",0);
 add_dialog_str(2,"If you wanted, you could take his bow.",0);
 add_dialog_choice(0,"Take the bow.");
 add_dialog_choice(1,"Leave it.");
 choice = run_dialog(1);
 if (choice == 1) {
  reward_give(453);
  message_dialog("You take Klinger's bow. It too, is scorched, but somehow it survived. It is a versatile piece of equipment and is yours now.","");
 }
 if (choice == 2) {
  award_party_xp(200,5);
  message_dialog("Out of respect for your fallen ally, you leave his bow in the place of his likely demise.","");
 } 
}

break;


beginstate 18;

if (get_sdf(5,13) == 0) {
 set_state_continue(13);
 block_entry(1);
 end();
}

if (get_sdf(5,15) == 0) {
 set_flag(5,15,1);
 message_dialog("The rubble blocks passage to the rest of the complex. You seriously wonder how you are going to escape. You better look around.","");
}

break;


beginstate 19;

activate_hidden_group(1);
set_name(7,"Olander");
set_name(8,"Nablar");
force_instant_terrain_redraw();
pause(5);

set_terrain(52,34,138);
set_terrain(51,34,138);
force_instant_terrain_redraw();
play_sound(108);
pause(5);

relocate_character(7,char_loc_x(7),char_loc_y(7) - 1);
force_instant_terrain_redraw();
pause(2);

set_terrain(52,33,138);
set_terrain(51,33,138);
force_instant_terrain_redraw();
play_sound(108);
pause(5);

relocate_character(7,char_loc_x(7),char_loc_y(7) - 1);
force_instant_terrain_redraw();
pause(2);

text_bubble_on_char(7,"My gods!");
force_instant_terrain_redraw();
pause(10);

relocate_character(8,char_loc_x(8) - 1,char_loc_y(8) - 1);
force_instant_terrain_redraw();
pause(2);

relocate_character(8,char_loc_x(8),char_loc_y(8) - 1);
force_instant_terrain_redraw();
pause(2);

text_bubble_on_char(7,"");
text_bubble_on_char(8,". . .");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(8,"");
force_instant_terrain_redraw();
pause(2);

 reset_dialog();
 add_dialog_str(0,"Two Nephilim make their way into the room using magical spells. The first is an old shaman. You believe his name is Olander. The second is much younger, and, if memory serves, is named Nablar.",0);
 add_dialog_str(1,"They survey the carnage in disbelief. Olander, especially, is shocked. A tear comes to his eye and he shakes his head. _Why Klinger? Why did you make me be responsible!?_",0);
 add_dialog_str(2,"You approach the old shaman. He explains, _Klinger sacrificed himself in an attempt to destroy Arivan and her captains. He succeeded, I see._",0);
 add_dialog_str(3,"You ask him how this carnage came about. He looks very guilty. _I didn't want to do it. He made me make him a potion, an explosive potion using the shards of an old beam projector. It worked all too well._",0);
 add_dialog_str(4,"_He gave his life so there could be peace in this forest. I can only hope this madness has ended forever._ You tell him about your adventures at the mine. _I hope that spirit leaves and haunts no one ever again._",0);
 add_dialog_str(5,"He sighs and clears his throat. _There's a passage to the south. It will take you to a place near the shore. You may use it to leave when you wish._",0);
 add_dialog_choice(0,"OK.");
 choice = run_dialog(1);

break;


beginstate 20;

if (get_sdf(5,16) == 0) {
 set_flag(5,16,1);
 message_dialog("This is an ancient lab with equipment much like that you saw in the lost mine. You suspect this is where Olander brewed the potion for Klinger.","");
}

break;


beginstate 21;

 reset_dialog();
 add_dialog_str(0,"This passage will take you away to a place near the shore. From there you can continue your survey of Valzakov Isle. Are you ready to leave yet?",0);
 add_dialog_choice(0,"Stay here.");
 add_dialog_choice(1,"Go down the passage.");
 choice = run_dialog(1);
 if (choice == 1)
  block_entry(1);
 if (choice == 2)
  move_to_new_town(8,16,16);

break;